#include <iostream>
#include <cmath>
#include <unordered_map>
#include <string>
#include <sstream>

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }

    for (int i = 2; i <= std::sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int get_closest_prime(int n) {
    if (is_prime(n)) {
        return n;
    }

    int next_prime = n + 1;
    while (!is_prime(next_prime)) {
        next_prime++;
    }

    int prev_prime = n - 1;
    while (!is_prime(prev_prime)) {
        prev_prime--;
    }

    if (n - prev_prime < next_prime - n) {
        return prev_prime;
    } else {
        return next_prime;
    }
}

int main() {
    std::unordered_map<std::string, std::string> words_to_nums = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };

    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::string word;
    std::vector<std::string> words;
    while (iss >> word) {
        words.push_back(word);
    }

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    std::string number;
    for (const auto& word : words) {
        auto it = words_to_nums.find(word);
        if (it != words_to_nums.end()) {
            number += it->second;
        } else {
            number = "";
            break;
        }
    }

    if (number.length() == 3 && std::all_of(number.begin(), number.end(), ::isdigit)) {
        int num = std::stoi(number);
        int lower_prime = num, upper_prime = num;
        while (true) {
            if (is_prime(lower_prime)) {
                std::cout << lower_prime << std::endl;
                break;
            }
            if (is_prime(upper_prime)) {
                std::cout << upper_prime << std::endl;
                break;
            }
            lower_prime--;
            upper_prime++;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}

